<template>
  <div class="app-container">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5" v-if="$store.state.currentJur.isAdd">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
            >新增</el-button>
          </el-col>
          <!--<el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
            >删除</el-button>
          </el-col>-->
        </el-row>

        <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="姓名" align="center" key="name" prop="name" width="100"  />
          <el-table-column label="电话" align="center" key="tel" prop="tel" :show-overflow-tooltip="true"  width="150" />
          <el-table-column label="身份证" align="center" key="cardNum" prop="cardNum" :show-overflow-tooltip="true"  width="100" />
          <el-table-column label="所属单位" align="center" key="unit" prop="unit" :show-overflow-tooltip="true"  width="100" />
          <el-table-column label="所属人" align="center" key="phonenumber" prop="unitPeople" width="120" />
          <el-table-column label="求职者状态" align="center" key="status" prop="status" width="100"  />
          <el-table-column label="上岗信息" align="center" key="info" prop="info" width="100"  />
          <el-table-column label="来源" align="center" key="origin" prop="origin" width="100"  />
          <el-table-column label="跟踪时间" align="center" key="time" prop="time" width="150"  />
          <el-table-column label="备注" align="center" key="note" prop="note" width="100"  />



          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button v-if="$store.state.currentJur.isResource"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
              >抢</el-button>
              <el-button v-if="$store.state.currentJur.isDel"
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
              >删除</el-button>
              <!--<el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
                <span class="el-dropdown-link">
                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="handleResetPwd" icon="el-icon-key"
                    >重置密码</el-dropdown-item>
                  <el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check"
                    >分配角色</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>-->
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
         <!-- 添加或修改用户配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="姓名" prop="nickName">
                    <el-input v-model="form.nickName" placeholder="请输入姓名" maxlength="30" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="电话" prop="phonenumber">
                    <el-input v-model="form.phonenumber" placeholder="请输入电话" maxlength="30" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="身份证" prop="nickName">
                    <el-input v-model="form.nickName" placeholder="请输入身份证" maxlength="30" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="所属单位">
                    <el-select v-model="form.roleIds" placeholder="请选择单位">
                        <el-option
                        v-for="item in roleOptions"
                        :key="item.roleId"
                        :label="item.roleName"
                        :value="item.roleId"
                        :disabled="item.status == 1"
                        ></el-option>
                    </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="所属人" prop="deptId">
                    <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="上岗信息" prop="info">
                        <el-input v-model="form.info" placeholder="请输入上岗信息" maxlength="30" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="跟踪信息" prop="info">
                        <el-input v-model="form.info" placeholder="请输入跟踪信息" maxlength="30" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="修改信息" prop="info">
                        <el-input v-model="form.info" placeholder="请输入修改信息" maxlength="30" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="备注">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
        </el-dialog>
</div>
</template>
<script>
    import Treeselect from "@riophae/vue-treeselect";
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    export default {
        name: 'user_manage',
        components: { Treeselect },
        data() {
            return {
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                },
                // 遮罩层
                loading: false,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                dateRange: [],
                //  表单参数
                form: {},
                // 总条数
                total: 0,
                // 用户表格数据
                tableData: [{
                    name: '张静',
                    tel:'13212345678',
                    cardNum:'456568900088xxx',
                    unit: '人事部',
                    unitPeople:'董事长',
                    status: '已投递',
                    info: '未入职',
                    origin:'智联招聘',
                    time: '2023-02-22 11:35',
                    note: '已面试'

                }],
                // 弹出层标题
                title: "",
                open: false,
                deptOptions:[
                    {
                        id:0,label:'总公司',
                        children:[{id:10,label:'总公司经理'},{id:11,label:'驻场'},{id:12,label:'分公司'},{id:13,label:'代理权限'}]},
                    {id:1,label:'加盟商',children:[]},
                ],
                roleOptions:[{
                    roleId: 1,
                    roleName: '超级管理员',
                    status:false,
                },{
                    roleId: 2,
                    roleName: '开发者',
                    status:false,
                }],
                 // 表单校验

                rules: {
                    userName: [
                    { required: true, message: "用户名称不能为空", trigger: "blur" },
                    { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
                    ],
                    nickName: [
                    { required: true, message: "用户昵称不能为空", trigger: "blur" }
                    ],
                    password: [
                    { required: true, message: "用户密码不能为空", trigger: "blur" },
                    { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
                    ],
                    email: [
                    {
                        type: "email",
                        message: "请输入正确的邮箱地址",
                        trigger: ["blur", "change"]
                    }
                    ],
                    phonenumber: [
                        { required: true, message: "电话不能为空", trigger: "blur" },
                        {
                            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                            message: "请输入正确的手机号码",
                            trigger: "blur"
                        }
                    ]
                },
            }
        },
        created() {
            // this.getList();
        },
        methods: {
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            getList() {
                // this.loading = true;
                // listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
                //     this.tableData = response.rows;
                //     this.total = response.total;
                //     this.loading = false;
                //     }
                // );
                const this_ = this
                this_.$http.get(this_.GLOBAL.REQUESTURL + "/gong_hai",{
                    pageNum: this_.queryParams.pageNum,
                    pageSize: this_.queryParams.pageSize,
                })
                .then(res => {
                    this_.tableData = res.data.list; //给查询列表赋值
                    this_.total = res.data.total;
                    this_.loading = false;
                })
                .catch(function(err) {
                    this_.tableData = [];
                    this_.total = 0;
                    this_.loading = false;
                });

            },
            handleAdd() {
                this.reset();
                this.title = "添加信息";
                this.open = true;
            },
             /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                this.open = true;
                this.title = "修改信息";
                this.form.password = "";
            },
            handleDelete(row) {
                this.$modal.confirm('确认要删除"' + row.username + '"用户吗？').then(function() {
                    // return changeUserStatus(row.userId, row.status);
                }).then(() => {
                    this.$modal.msgSuccess( "删除成功");
                }).catch(function() {
                    this.$modal.msgWarning( "删除失败");
                });
            },
            submitForm: function() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                    }
                })
            },
            handleExport() {},
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.userId);
                this.single = selection.length != 1;
                this.multiple = !selection.length;
            },
             // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 用户状态修改
            handleStatusChange(row) {
                let text = row.status === "0" ? "启用" : "停用";
                this.$modal.confirm('确认要"' + text + '""' + row.username + '"用户吗？').then(function() {
                    // return changeUserStatus(row.userId, row.status);
                }).then(() => {
                    this.$modal.msgSuccess(text + "成功");
                }).catch(function() {
                    row.status = row.status === "0" ? "1" : "0";
                });
            },
             // 表单重置
            reset() {
                this.form = {
                    userId: undefined,
                    deptId: undefined,
                    userName: undefined,
                    nickName: undefined,
                    password: undefined,
                    phonenumber: undefined,
                    email: undefined,
                    sex: undefined,
                    status: "0",
                    remark: undefined,
                    postIds: [],
                    roleIds: []
                };
                this.resetForm("form");
            },
        }
    }
</script> 